Attribute VB_Name = "OTSTDLIB_Parse"
'============================================================
' OT Standard Library: Visual Basic
' Parse.bas
'   Description:    Used to parse strings
'   Return Type:    String
'------------------------------------------------------------
'------------------------------------------------------------
' Example of How to Call Function
' -------------------------------
'
' +----------------------------------------------------------+
' |   This code block parses B in the the string ABC to C    |
' +----------------------------------------------------------+
'
' Parse("ABC","B",C"  )
' 'Returns AAC
'============================================================

Option Explicit


Function Parse(ByVal OldStr As String, ByVal Bad As String, ByVal Good As String) As String

Parse = Replace(OldStr, Bad, Good)

Exit Function
If (InStr(OldStr, Bad)) Then
    'do nothing
Else
    Parse = OldStr
    Exit Function
End If

Dim NewStr As String
Dim Temp As String
Dim Counter As Long
NewStr = ""

For Counter = 0 To Len(OldStr)
    NewStr = NewStr & Right(Left(OldStr, Counter), 1)
    
    If Right(NewStr, Len(Bad)) = Bad Then
        Temp = Left(NewStr, (Len(NewStr) - Len(Bad)))
        NewStr = Temp
        NewStr = NewStr & Good
    End If

Next Counter
Parse = NewStr

End Function
